<?php /*a:2:{s:37:"E:\project\tp\view\catgory\index.html";i:1621606847;s:37:"E:\project\tp\view\layout\layout.html";i:1621424375;}*/ ?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title><?php echo htmlentities($title); ?></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="/static/layui/css/layui.css"/>
       
    </head>
    <body>
        <div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">layout demo</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <!-- 移动端显示 -->
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
        <i class="layui-icon layui-icon-spread-left"></i>
      </li>
      
      <li class="layui-nav-item layui-hide-xs"><a href="">nav 1</a></li>
      <li class="layui-nav-item layui-hide-xs"><a href="">nav 2</a></li>
      <li class="layui-nav-item layui-hide-xs"><a href="">nav 3</a></li>
      <li class="layui-nav-item">
        <a href="javascript:;">nav groups</a>
        <dl class="layui-nav-child">
          <dd><a href="">menu 11</a></dd>
          <dd><a href="">menu 22</a></dd>
          <dd><a href="">menu 33</a></dd>
        </dl>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
        <a href="javascript:;">
          <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img">
         <?php echo session('username')?>     </a>
        <dl class="layui-nav-child">
          <dd><a href="">Your Profile</a></dd>
          <dd><a href="">Settings</a></dd>
          <dd><a href="<?php echo url('Login/logout'); ?>">Sign out</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
           <li class="layui-nav-item layui-this"><a href="<?php echo url('/Index/index'); ?>">首页</a></li>
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">系统设置</a>
          <dl class="layui-nav-child">
            <dd><a href="<?php echo url('/User'); ?>">用户管理</a></dd>
            <dd><a href="<?php echo url('/Admin'); ?>">管理员管理</a></dd>
            <dd><a href="<?php echo url('/Storage'); ?>">库位信息</a></dd>
            <dd><a href="<?php echo url('/Catgory'); ?>">物品分类</a></dd>
            <dd><a href="<?php echo url('/Goods'); ?>">物品信息</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">仓库管理</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">入库</a></dd>
            <dd><a href="javascript:;">领料</a></dd>
            <dd><a href="javascript:;">出库</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item"><a href="javascript:;">click menu item</a></li>
        <li class="layui-nav-item"><a href="">the links</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;"><div class="layui-btn-group demoTable">

    <button data-method="offset" data-type="layerOpen" class="layui-btn layui-btn-normal" >添加分类</button>
</div>

<table class="layui-table "  lay-data="{ url:'/Catgory/show', page:true,limit:10, id:'idTest'}" lay-filter="demo">
    <thead>
        <tr>
            <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
            <th lay-data="{field:'id', width:80, sort: true, fixed: true}">ID</th>
            <th lay-data="{field:'catgory_name'}">分类名称</th>
            <th lay-data="{field:'parent_id'}">上级分类</th>
            <th lay-data="{field:'desc'}">分类描述</th>
            <th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}"></th>
        </tr>
    </thead>
</table>





<script type="text/html" id="barDemo">
    <a style="display: none" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a style="display: none" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="/static/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['table', 'layer','form'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var $ = layui.jquery
                , form = layui.form;

        //检查项目添加到下拉框中
        $.ajax({
            url: '/Catgory/tree_list',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                $.each(data, function (index, item) {
                
                    $('#catgory_name').append(new Option( item.split + item.catgory_name,item.id));// 下拉菜单里添加元素
                });
                form.render("select");

//重新渲染 固定写法
            }
        })




    //监听工具条
    table.on('tool(demo)', function (obj) {
        var data = obj.data;
        if (obj.event === 'detail') {
            layer.msg('ID：' + data.id + ' 的查看操作');
        } else if (obj.event === 'del') {
//                  var ID=[];
//                    ID.id=data.id;
//                    console.log(ID);
            layer.confirm('真的删除行么', function (index) {

                $.ajax({
                                url: '/Catgory/delete',
                                type: 'POST',
                                data: "id=" + data.id,
                                dataType: "json",

                                success: function (data) {
                                        if (data) {
                                                layer.alert("提交成功！")
                                        }
                                        else {
                                                layer.alert("提交失败！")
                                        }
                                },
                                error: function (e) {
                                    layer.alert("提交失败！")
                                },
            
                        });

                obj.del();
                layer.close(index);
            });
        } else if (obj.event === 'edit') {
            layer.open({
                type: 1 //Page层类型
                , area: ['500px', '300px']
                , title: '编辑用户'
                , shade: false//遮罩透明度
                , maxmin: true //允许全屏最小化
                , anim: 1 //0-6的动画形式，-1不开启
                , content: $("#editCatgory")
            });
            $('#editCatgory').find('input[name="catgory_name"]').val(data.catgory_name);
            $('#editCatgory').find('input[name="desc"]').val(data.desc);
            $('#editCatgory').find('input[name="id"]').val(data.id);
//                layer.alert('编辑行：<br>' + JSON.stringify(data))
        }
    });
    var active = {
        layerOpen: function () {
            layer.open({
                type: 1 //Page层类型
                , area: ['500px', '300px']
                , title: '添加用户'
                , shade: false//遮罩透明度
                , maxmin: true //允许全屏最小化
                , anim: 1 //0-6的动画形式，-1不开启
                , content: $("#addCatgory")
            });
        }

    }



    $('.demoTable .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    $('#addCatgory #btn_add').on('click', function () {

        var data = $('#addCatgory input[name="catgory_name"]').val();
        var data2 = $('#addCatgory input[name="desc"]').val();

        if (data !== "" && data2 !== "") {
            $.ajax({
                            url: ' /Catgory/save',
                            type: 'POST',
                            data: $('#addCatgory').find('form').serialize(),
                            dataType: "json",

                            success: function (data) {

                                    if (data) {
                                            layer.alert("提交成功！")
                                    }
                                    else {
                                            layer.alert("提交失败！")
                                    }
                            },
                            error: function (e) {
                                layer.alert("提交失败！")
                            },
            
                    });
        }




    });

    $('#editCatgory #btn_edit').on('click', function () {



    $.ajax({
                url: '/Catgory/update',
                        type: 'POST',
                        data: $('#editCatgory').find('form').serialize(),
                        dataType: "json",
                        success: function (data) {

                            if (data) {
                                layer.alert("修改成功！")
                            }
                            else {
                                layer.alert("修改失败！")
                            }
                        },
                        error: function (e) {
                        layer.alert("修改失败！")
                        },
            
            });
    });
    });
</script>

<div style="display: none" id="addCatgory">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-block">
                <input type="text" name="catgory_name" lay-verify="required" autocomplete="off"lay-reqtext="必须输入库位名" placeholder="请输入用户名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上级分类</label>
            <div class="layui-input-block">
                <select  id="catgory_name" name="parent_id" lay-verify="">
                    <option value="0">上级分类</option>

                </select>  
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="desc" lay-verify="required" lay-reqtext="请输入描述" placeholder="请输入描述" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="btn_add" type="submit" class="layui-btn" lay-submit="" lay-filter="">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div>

<div style="display: none" id="editCatgory">
    <form class="layui-form" >
        <input type="hidden" name="id" value="" />
        <div class="layui-form-item">
            <label class="layui-form-label">库位名称</label>
            <div class="layui-input-block">
                <input type="text" name="catgory_name" lay-verify="required" autocomplete="off"lay-reqtext="必须输入库位名" placeholder="请输入用户名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="desc" lay-verify="required" lay-reqtext="请输入描述" placeholder="请输入描述" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="btn_edit" type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div></div>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    底部固定区域
  </div>
</div>
<!--<script src="/static/layui/layui.js"></script>-->
<script>
//JS 
layui.use(['element', 'layer', 'util'], function(){
  var element = layui.element
  ,layer = layui.layer
  ,util = layui.util
  ,$ = layui.$;
  
  //头部事件
  util.event('lay-header-event', {
    //左侧菜单事件
    menuLeft: function(othis){
      layer.msg('展开左侧菜单的操作', {icon: 0});
    }
    ,menuRight: function(){
      layer.open({
        type: 1
        ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
        ,area: ['260px', '100%']
        ,offset: 'rt' //右上角
        ,anim: 5
        ,shadeClose: true
      });
    }
  });
  
});
</script>
</body>
   
</html>
